import controlP5.*;

public class Menu {
	
	//BUTTONS
	controlP5.Button B_View1;	//Top Artist View
	controlP5.Button B_View2;	//HeatCalendar View
	controlP5.Button B_View3;	//Song View
	controlP5.Button B_View4;	//Ignore Artist View
	
	controlP5.Button B_Sex0;	//"All" Sexes
	controlP5.Button B_Sex1;	//Females
	controlP5.Button B_Sex2;	//Males
	
	controlP5.Button B_Add;		//Used to add filter to visualization
	controlP5.Button B_Ctry;	//Used to select all nationalities
	
	controlP5.Button B_Add05, B_Add06, B_Add07, B_Add08, B_Add09, B_Add00; 
	
	//RANGES
	Range R_Age;
	
	//LISTS
	ListBox LB_Cntry;
	
	//LABELS
	Textlabel L_Age;
	
	public Menu() {	
		// TABS ----------
		B_View1 = GLOBAL.controlP5.addButton("view1", 0, 0, 25, 100, 25);
        	B_View1.setLabel("Top Artists");
        	B_View1.setColorCaptionLabel(0);
        	B_View1.setColorForeground(GLOBAL.colorTabMouseOver);
		
        B_View2 = GLOBAL.controlP5.addButton("view2", 0, 102, 25, 100, 25);
        	B_View2.setLabel("Heat Calendar");
        	B_View2.setColorCaptionLabel(0);
        	B_View2.setColorForeground(GLOBAL.colorTabMouseOver);
        
        B_View3 = GLOBAL.controlP5.addButton("view3", 0, 204, 25, 100, 25);
        	B_View3.setLabel("Search");
        	B_View3.setColorCaptionLabel(0);
        	B_View3.setColorForeground(GLOBAL.colorTabMouseOver);
        	
        B_View4 = GLOBAL.controlP5.addButton("view4", 0, 920, 25, 100, 25);
        	B_View4.setLabel("Ignored Artists");
        	B_View4.setColorCaptionLabel(0);
        	B_View4.setColorForeground(GLOBAL.colorTabMouseOver);
        
        //-----------------
        
        R_Age = GLOBAL.controlP5.addRange("age", 13, 65, 13, 65, 0, 110, 150, 16);
        	R_Age.setDecimalPrecision(0);
        	R_Age.setLabel("");
        	R_Age.setColorValueLabel(0);
        	R_Age.setColorForeground(GLOBAL.colorTabSelected);
        	R_Age.setColorActive(GLOBAL.colorTabMouseOver);
        	R_Age.setColorBackground(GLOBAL.colorTabDeselected);
        	
        B_Sex0 = GLOBAL.controlP5.addButton("sex0", 0, 0, 170, 100, 20);
        	B_Sex0.setLabel("All");
        	B_Sex0.setColorCaptionLabel(0);
        	B_Sex0.setColorForeground(GLOBAL.colorTabMouseOver);
        	
        B_Sex1 = GLOBAL.controlP5.addButton("sex1", 0, 0, 192, 100, 20);
        	B_Sex1.setLabel("Females");
        	B_Sex1.setColorCaptionLabel(0);
        	B_Sex1.setColorForeground(GLOBAL.colorTabMouseOver);
        	
        B_Sex2 = GLOBAL.controlP5.addButton("sex2", 0, 0, 214, 100, 20);
        	B_Sex2.setLabel("Males");
        	B_Sex2.setColorCaptionLabel(0);
        	B_Sex2.setColorForeground(GLOBAL.colorTabMouseOver);
        	
        B_Add = GLOBAL.controlP5.addButton("add", 0, 75, 710, 25, 25);
        	B_Add.setImages(GLOBAL.processing.loadImage("plus.gif"), GLOBAL.processing.loadImage("plus2.gif"), GLOBAL.processing.loadImage("plus3.gif"));
        
        B_Ctry = GLOBAL.controlP5.addButton("all_cntry", 0, 0, 280, 100, 20);
        	B_Ctry.setLabel("All Countries");
        	GLOBAL.setButtonColors(B_Ctry);
        	
        LB_Cntry = GLOBAL.controlP5.addListBox("countries", 0, 320, 168, 200);
        	LB_Cntry.setLabel("Choose one country.");
        	LB_Cntry.setColorForeground(GLOBAL.colorTabSelected);
        	LB_Cntry.setColorActive(GLOBAL.colorTabMouseOver);
        	LB_Cntry.setColorBackground(GLOBAL.colorListBox);
        	LB_Cntry.setColorLabel(0);
        	LB_Cntry.setColorValue(0);
        	populateCountries();
        
        L_Age = GLOBAL.controlP5.addTextlabel("age_label", "65", 155, 115);
        	L_Age.setColorValueLabel(0);
        	
        //------------------
        
        B_Add05 = GLOBAL.controlP5.addButton("yr_05", 0, 0, 170, 100, 25);
        	GLOBAL.setButtonColors(B_Add05);
        	B_Add05.setLabel("2005");
        	B_Add05.setVisible(false);
        	
        B_Add06 = GLOBAL.controlP5.addButton("yr_06", 0, 0, 200, 100, 25);
        	GLOBAL.setButtonColors(B_Add06);
        	B_Add06.setLabel("2006");
        	B_Add06.setVisible(false);
        	
        B_Add07 = GLOBAL.controlP5.addButton("yr_07", 0, 0, 230, 100, 25);
        	GLOBAL.setButtonColors(B_Add07);
        	B_Add07.setLabel("2007");
        	B_Add07.setVisible(false);
        	
        B_Add08 = GLOBAL.controlP5.addButton("yr_08", 0, 0, 260, 100, 25);
        	GLOBAL.setButtonColors(B_Add08);
        	B_Add08.setLabel("2008");
        	B_Add08.setVisible(false);
        	
        B_Add09 = GLOBAL.controlP5.addButton("yr_09", 0, 0, 290, 100, 25);
        	GLOBAL.setButtonColors(B_Add09);
        	B_Add09.setLabel("2009");
        	B_Add09.setVisible(false);
        
        B_Add00 = GLOBAL.controlP5.addButton("yr_00", 0, 0, 320, 100, 25);
        	GLOBAL.setButtonColors(B_Add00);
        	B_Add00.setLabel("All Years");
        	B_Add00.setVisible(false);
        	
	}
	
	public void hideFilterMenu() {
		R_Age.setVisible(false);
		B_Sex0.setVisible(false);
		B_Sex1.setVisible(false);
		B_Sex2.setVisible(false);
		B_Add.setVisible(false);
		B_Ctry.setVisible(false);
		LB_Cntry.setVisible(false);
		L_Age.setVisible(false);
	}
	
	public void showAll() {
		R_Age.setVisible(true);
		B_Sex0.setVisible(true);
		B_Sex1.setVisible(true);
		B_Sex2.setVisible(true);
		B_Add.setVisible(true);
		B_Ctry.setVisible(true);
		LB_Cntry.setVisible(true);
		L_Age.setVisible(true);
	}
	
	public void setHeatMenuVisibility(boolean v) {
		B_Add05.setVisible(v);
		B_Add06.setVisible(v);
		B_Add07.setVisible(v);
		B_Add08.setVisible(v);
		B_Add09.setVisible(v);
		B_Add00.setVisible(v);
	}
	
	private void populateCountries() {
		for(int x=0; x<GLOBAL.ALL_COUNTRIES.size(); ++x) {
			LB_Cntry.addItem(GLOBAL.ALL_COUNTRIES.get(x), x);
		}
	}
	
	public void updateAgeMax() {
		L_Age.setValueLabel("" + GLOBAL.AGE_MAX);
	}
	
	public int setActiveTab(String tabName) {
		//TOP ARTISTS VIEW
		if(tabName.equals("view1")) {
			B_View1.setColorBackground(GLOBAL.colorTabSelected);
			B_View2.setColorBackground(GLOBAL.colorTabDeselected);
			B_View3.setColorBackground(GLOBAL.colorTabDeselected);
			B_View4.setColorBackground(200);
			return 0;
		}
		
		//HEAT CALENDAR VIEW
		if(tabName.equals("view2")) {
			B_View1.setColorBackground(GLOBAL.colorTabDeselected);
			B_View2.setColorBackground(GLOBAL.colorTabSelected);
			B_View3.setColorBackground(GLOBAL.colorTabDeselected);
			B_View4.setColorBackground(200);
			return 1;
		}
		
		//SONG VIEW
		if(tabName.equals("view3")) {
			B_View1.setColorBackground(GLOBAL.colorTabDeselected);
			B_View2.setColorBackground(GLOBAL.colorTabDeselected);
			B_View3.setColorBackground(GLOBAL.colorTabSelected);
			B_View4.setColorBackground(200);
			return 2;
		}
		
		if(tabName.equals("view4")) {
			B_View1.setColorBackground(GLOBAL.colorTabDeselected);
			B_View2.setColorBackground(GLOBAL.colorTabDeselected);
			B_View3.setColorBackground(GLOBAL.colorTabDeselected);
			B_View4.setColorBackground(GLOBAL.colorTabSelected);
			return 3;
		}
		
		return -1;
	}
	
	public int setActiveSex(String tabName) {
		if(tabName.equals("sex0")) {
			B_Sex0.setColorBackground(GLOBAL.colorTabSelected);
			B_Sex1.setColorBackground(GLOBAL.colorTabDeselected);
			B_Sex2.setColorBackground(GLOBAL.colorTabDeselected);
			return 0;
		}
		
		if(tabName.equals("sex1")) {
			B_Sex0.setColorBackground(GLOBAL.colorTabDeselected);
			B_Sex1.setColorBackground(GLOBAL.colorTabSelected);
			B_Sex2.setColorBackground(GLOBAL.colorTabDeselected);
			return 1;
		}
		
		if(tabName.equals("sex2")) {
			B_Sex0.setColorBackground(GLOBAL.colorTabDeselected);
			B_Sex1.setColorBackground(GLOBAL.colorTabDeselected);
			B_Sex2.setColorBackground(GLOBAL.colorTabSelected);
			return 2;
		}
		
		return -1;
	}
}
